<template>
  <GlobalHeader
    :class="[
      fixedList.includes($route.meta.title) ? 'fixed' : 'relative',
      top ? 'sticky' : '',
    ]"
  />
  <div style="min-height: 100vh">
    <router-view />
  </div>
  <GlobalFooter v-if="$router.currentRoute.value.name !== 'Login'" />
</template>
<script lang="ts" setup>
import { onMounted, onUnmounted, ref } from "vue";
import GlobalHeader from "@/components/GlobalHeader/index.vue";
import GlobalFooter from "@/components/GlobalFooter/index.vue";
import { useRouter } from "vue-router";

const router = useRouter();

const top = ref(false);
const handleScroll = (e: any) => {
  // 处理滚动事件的逻辑
  const h = window.scrollY;
  top.value = h > 1;
};
const fixedList: any = ["首页", "责任", "商业客户"];
const handleScrollToTop = () => {
  window.scrollTo({ top: 0 });
};

onMounted(() => {
  // 组件挂载时，添加滚动事件监听
  window.addEventListener("scroll", handleScroll);
  // 组件挂载时，添加路由切换监听
  router.afterEach(() => {
    handleScrollToTop();
  });
});

onUnmounted(() => {
  // 组件销毁时，移除滚动事件监听
  window.removeEventListener("scroll", handleScroll);
  handleScrollToTop();
});
</script>
<style lang="less">
#app {
  // max-width: 1920px;
  min-width: 1090px;
  margin: auto;
  font-family: Avenir, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-align: center;
  color: #2c3e50;
}
.relative {
  width: 100%;
  position: relative;
  z-index: 100;
  transition: 0.3s all;
  .header-nav {
    box-shadow: rgba(146, 157, 154, 0.15) 0px 4px 10px 0px;
    background: rgba(255, 255, 255, 1);
  }
  .nav-li,
  .nav-li1 {
    color: #000000 !important;
  }
}
.fixed {
  width: 100%;
  position: fixed;
  top: 0;
  z-index: 100;
  transition: 0.3s all;
  .header-nav {
    background: rgba(255, 255, 255, 0);
  }
  .nav-li,
  .nav-li1 {
    color: #f5f5f5 !important;
  }
}
.sticky {
  .header-nav {
    box-shadow: rgba(146, 157, 154, 0.15) 0px 4px 10px 0px;
    background: rgba(255, 255, 255, 1);
  }
  .nav-li,
  .nav-li1 {
    color: #000000 !important;
  }
}
nav {
  padding: 30px;
  .link {
    padding: 20px;
  }
}

#nav a {
  font-weight: bold;
  color: #2c3e50;
}

#nav a.router-link-exact-active {
  color: #42b983;
}
</style>
